package com.mikao.controller.homePage;

import com.mikao.dto.bo.AdvForm;
import com.mikao.dto.bo.ReqDataTableDto;
import com.mikao.dto.vo.AdvDto;
import com.mikao.dto.vo.RspDataTableDto;
import com.mikao.service.AdvService;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


/**
 * @author KennyDavid
 */
@RestController
@RequestMapping(value = "/management", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Scope("prototype")
public class AdvController {

    private AdvService advService;

    public AdvController(AdvService advService) {
        this.advService = advService;
    }

    @GetMapping("/getAdvList")
    public RspDataTableDto<AdvDto> getAdvList(@ModelAttribute ReqDataTableDto dataTableDTO, @RequestParam(required = false) String nameOrMobile) {
        return advService.getAdvList(dataTableDTO, nameOrMobile);
    }

    @PostMapping("/removeAdv/{id}")
    public void removeAdv(@PathVariable Long id) {
        advService.removeAdv(id);
    }

    @PostMapping("/addAdv")
    public Boolean addAdv(AdvForm advForm) {
        return advService.addAdv(advForm);
    }
}